package org.example.supermarket;

import org.example.activity.FullMinusActivity;
import org.example.goods.Goods;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Hello world!
 *
 */
public class Supermarket implements FullMinusActivity {

    Map<String,Goods> goodsMap = new HashMap<>();

    //添加商品到超市
    public void addGoods(String goodsNumber,Goods goods){
        goodsMap.put(goodsNumber,goods);
    }

    // 满减优惠活动
    public BigDecimal computePrice(BigDecimal fullPrice, BigDecimal preferentialPrice, BigDecimal price) {

        if (price.compareTo(fullPrice) > -1 ){
            return price.subtract(preferentialPrice);
        }
        return price;
    }

    public Goods getGoodsByNo(String goodsNumber){
        Goods goods = goodsMap.get(goodsNumber);
        if (goods == null){
            throw new RuntimeException("没有该商品");
        }
        return goods;
    }

    public void setDiscount(String goodsNumber,BigDecimal discount){
        Goods goods = goodsMap.get(goodsNumber);
        if (goods == null){
            throw new RuntimeException("没有该商品");
        }
        goods.setDiscount(discount);
    }

}
